package your_car_status

class Customer {

    String identification
    String email
    String confirmEmail
    String name
    String phoneNumber
    String address
    String password
    String confirmPassword
    
    static belongsTo = [repairShop: RepairShop]
    static hasMany=[vehicle:Vehicle]
    static constraints = {
        id unique: true, blank: false, size: 5..10
        email (unique: true, blank: false, email: true,  validator: {email, obj ->
         def confirmEmail = obj.properties['confirmEmail']
         if(confirmEmail == null) return true 
         if (confirmEmail == email)return true 
         else return['invalid.error']
     })
        confirmEmail unique: true, blank: false, email: true
        name blank: false ,  matches: "[a-zA-Z- ]+"
        address blank : false
        phoneNumber blank : false , size : 7..12 , matches: "[(0-9)]+"
        password(blank: false, size: 5..15 , password:true, validator: {password, obj ->
         def confirmPassword = obj.properties['confirmPassword']
         if(confirmPassword == null) return true // skip matching password validation (only important when setting/resetting pass)
         confirmPassword == password ? true : ['invalid.matchingpasswords']
     })
        confirmPassword blank: false, size: 5..15 , password:true
    }
    
}